
const util = require('../../utils/util.js');
const api = require('../../config/api.js');
// pages/my-collection/list.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight: '',
    scrollTop: 0,
    pagination: {
      page: 1,
      size: 5,
      id: 0
    },
    totalPage: 0,
    hidden: false,
    pageTip: '加载中...',
    noData: false,
    rooms: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id)
    this.data.pagination.id = options.id;
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res)
        that.setData({
          scrollHeight: res.windowHeight
        });

      }
    });
    that.getList();
  },
  /**
   * 绑定滚动加载事件
  */
  bindDownLoad: function (event) {
    let self = this;
    if (self.data.pagination.page == self.data.totalPage) {
      self.setData({
        noData: true
      });
      return false;
    }
    if (self.data.pagination.page != self.data.totalPage) {
      self.data.pagination.page += 1;
    }
    this.getList();
  },
  /**
   * 获取自己发布的房源信息系列
  */
  getList: function () {
    let self = this;
    self.setData({
      hidden: false
    });
    util.request(api.roomCollectionListUrl, self.data.pagination, 'post').then(function (res) {
      if (res.errno === 0) {
        console.log(res.data.result)
        self.data.rooms.push.apply(self.data.rooms, res.data.result.data);
        self.setData({
          rooms: self.data.rooms,
        });
        console.log(self.data.rooms)
        self.data.totalPage = res.data.result.totalPages
      }
      self.setData({
        hidden: true
      });
    });
  }
})